{include file='public/header' /}
<style type="text/css">
    .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
    .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
    .header button{float: right;margin-top: -5px;}
</style>
</head>
<body style="padding: 10px;">
<div class="header">
    <span>小区列表</span>
        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="add">添加</button>
    <div></div>

</div>
<div class="layui-form" lay-filter="form" action="">
    <div class="layui-form-item"  style="padding-top: 15px">
        <label class="layui-form-label">搜索小区</label>
<!--        <div class="layui-input-inline">-->
<!--            <select name="provid" id="provid" lay-filter="provid" value="">-->
<!--                {$s_html|raw}-->
<!--            </select>-->
<!--        </div>-->
<!--        <div class="layui-input-inline">-->
<!--            <select name="cityid" id="cityid" lay-filter="cityid" value="">-->
<!--                <option value="" disabled>请选择市</option>-->
<!--            </select>-->
<!--        </div>-->
<!--        <div class="layui-input-inline">-->
<!--            <select name="bc_area_id" id="bc_area_id" lay-filter="bc_area_id" value="" >-->
<!--                <option value="" disabled>请选择县/区</option>-->
<!--            </select>-->
<!--        </div>-->
        <div class="layui-input-inline layui-show-xs-block">
            <input type="text" name="rq_name" placeholder="请输入小区名称" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline layui-show-xs-block">
            <button class="layui-btn" id="select"  lay-submit lay-filter="select"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
</div>
<table id="lists" lay-filter="lists"></table>


<script type="text/javascript">
    layui.use(['layer','form','table'],function(){
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        // form.on('switch', function(data){
        //     layer.msg('正在提交请稍候。。。', {icon: 16,time: 100000,shade : [0.5 , '#000' , true]});
        //     $.post('__PUBLIC__/admin/BusinessCircle/status',{'id':data.elem.id,'tenant_status':data.elem.checked},function (res){
        //         if(res.code>0){
        //             layer.alert(res.msg,{icon:2});
        //             if(data.elem.checked == false){
        //                 data.elem.checked = true
        //             }else {
        //                 data.elem.checked = false
        //             }
        //             form.render();
        //         }else {
        //             layer.msg(res.msg,{icon:1,time:1100});
        //             //location.reload();
        //         }
        //     },'json');
        // });
        form.on('submit(select)', function(data){
            table.render({
                elem: '#lists'
                ,height: 'full-144'
                ,url: '__PUBLIC__/admin/ResidentialQuarters/check' //数据接口
                ,page: true //开启分页
                ,where:form.val("form")
                // ,size: 'sm'
                ,cellMinWidth:60
                // ,even: true
                ,cols: [[ //表头
                    // {field: 'a1', title: '省', }
                    // ,{field: 'a2', title: '市', minWidth:120}
                    // ,{field: 'a3', title: '区', minWidth:120}
                    // ,{field: 'a4', title: '地区id', minWidth:100}
                    {field: 'rq_bc_id', title: '商圈id',minWidth:120}
                    ,{field: 'rq_id', title: '小区id',minWidth:120}
                    ,{field: 'rq_name', title: '小区名称', minWidth:120}
                    ,{field: 'rq_create_time', title: '添加时间', minWidth:180, }
                    ,{field: 'operation', title: '操作',minWidth: 120}
                ]]
            });
            return false;
        });
        form.on('select(provid)', function(data){
            console.log(data.elem.value);
            if (data.elem.value == undefined||data.elem.value == null||data.elem.value == "") {
                $("select[name=cityid]").empty();
                $("select[name=bc_area_id]").empty();
                form.render();
                return;
            }
            $.post('__PUBLIC__/admin/ResidentialQuarters/shi',{'p1':data.elem.value},function (res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                }else {
                    layer.msg(res.msg,{icon:1,time:1100});
                    $("select[name=cityid]").empty();
                    $("select[name=bc_area_id]").empty();
                    $("select[name=cityid]").append(res.data);

                    form.render();    //刷新select选择框渲染
                }
            },'json');
        });
        form.on('select(cityid)', function(data){
            console.log(data);
            if (data.elem.value == undefined||data.elem.value == null||data.elem.value == "") {
                $("select[name=bc_area_id]").empty();
                form.render();
                return;
            }
            $.post('__PUBLIC__/admin/ResidentialQuarters/qu',{'p2':data.elem.value},function (res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                }else {
                    layer.msg(res.msg,{icon:1,time:1100});
                    $("select[name=bc_area_id]").empty();
                    $("select[name=bc_area_id]").append(res.data);

                    form.render();    //刷新select选择框渲染
                }
            },'json');
        });
        form.on('submit(editor)', function(data){
            layer.open({
                type: 2,
                title: data.elem.id>0?'编辑资料':'添加人员',
                shade: 0.3,
                area: ['620px', '480px'],
                content: '__PUBLIC__/admin/ResidentialQuarters/add?id='+data.elem.id

            });
        });
        form.on('submit(add)', function(data){
            layer.open({
                type: 2,
                title: '添加小区',
                shade: 0.3,
                area: ['620px', '480px'],
                content: '__PUBLIC__/admin/ResidentialQuarters/add?id='+data.elem.id,

            });
        });
        form.on('submit(del)', function(data){
            var item_table = table.cache['lists'];
            console.log(item_table);
            console.log(data);
            for (var index in item_table) {
                if(item_table[index].rq_id == data.elem.id){
                    var name = item_table[index].rq_name;
                }
            }
            layer.confirm('确认要删除'+name+'吗？',{
                btn: ['是的','取消'] //按钮
            }, function(){
                layer.msg('正在提交删除。。。', {icon: 16,time: 10000,shade : [0.5 , '#000' , true]});
                $.post('__PUBLIC__/admin/ResidentialQuarters/del',{'rq_id':data.elem.id},function (res){
                    if(res.code>0){
                        layer.alert(res.msg,{icon:2});
                    }else {
                        layer.msg(res.msg,{icon:1,time:1100});
                        location.reload();
                    }
                },'json');
            });
        });
        $(document).ready(function(){
            $("#select").click();
        });
    });
</script>
</body>
</html>
